/**
 * Copyright (c) 2019 EOVA.CN. All rights reserved.
 * 
 * Licensed to: 珠海易立方软件有限公司(414693478@qq.com)
 * Licensed under the EPPL license: http://eova.cn/eppl.txt
 * Software copyright registration number:2018SR1012969
 * For authorization, please contact: admin@eova.cn
 */
package com.eova.model;

import com.eova.common.base.BaseModel;
import com.eova.config.EovaConst;

public class User extends BaseModel<User> {

	private static final long serialVersionUID = 1064291771401662738L;

	public static final User dao = new User().dao();

	public Role role;

	public Object getId() {
		return this.get("id");
	}

	public int getRid(){
		// 优先获取临时切换角色
		Integer suRid = this.getInt("su_rid");
		if (suRid != null) {
			return suRid;
		}

		return this.getInt("rid");
	}

	/**
	 * 是否超级管理员
	 * @return
	 */
	public boolean isAdmin(){
		return getIsAdmin();
	}
	
	// 为兼容模版取值
	public boolean getIsAdmin(){
		// 按真实角色判断是否为管理员
		if (this.getInt("rid") == EovaConst.ADMIN_RID) {
			return true;
		}
		return false;
	}

	public void initRole() {
		this.role = Role.dao.findById(this.getInt("rid"));
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public String getName() {
		return this.getStr("name");
	}

	public int getOrgId() {
		return this.getInt("org_id");
	}
}